package pers.myutil.local.encryption;

import pers.myutil.local.conversion.data.ByteConversion;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


public class SHA256 {


    /**
     * 获取SHA256加密
     * @param parameter 参数
     * @throws NoSuchAlgorithmException
     */
    public static String getSHA256(String parameter) throws NoSuchAlgorithmException{
        MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
        messageDigest.update(parameter.getBytes());
        return ByteConversion.byteToHex(messageDigest.digest());
    }

    /**
     * 获取加盐的SHA256
     * @param parameter 参数
     * @param salt 盐值
     * @return 带盐的SHA256
     * @throws NoSuchAlgorithmException
     */
    public static String getSHA256(String parameter,String salt) throws NoSuchAlgorithmException {
        return getSHA256(parameter+salt);
    }


}
